package com.ki.rent.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ki.rent.entity.Style;
import com.ki.rent.service.StyleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 */
@Controller
@RequestMapping("/rent/style")
public class StyleController {


    @Autowired
    private StyleService styleService;

    //查看我自己发布的装修
    @RequestMapping("/myStyle")
    public String myStyle(Model model, HttpServletRequest request){
        Integer userId = (Integer) request.getSession().getAttribute("userId");
        QueryWrapper<Style> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        Style style = styleService.getOne(wrapper);
        String styleImg = style.getStyleImg();
        String[] split = styleImg.split("~");
        String img1 = split[0];
        String img2 = split[1];
        String img3 = split[2];
        model.addAttribute("img1",img1);
        model.addAttribute("img2",img2);
        model.addAttribute("img3",img3);
        model.addAttribute("style",style);
        return "style/mystyle";
    }

    //到所有装修页面
    @RequestMapping("/allStyle")
    public String allStyle(){
        return "style/styleindex";
    }


    //展示装修页面
    @RequestMapping("/showStyle/{styleId}")
    public String showStyle(@PathVariable("styleId") Integer styleId, Model model, HttpServletRequest request){
        Style style = styleService.getById(styleId);
        String styleImg = style.getStyleImg();
        String[] split = styleImg.split("~");
        String img1 = split[0];
        String img2 = split[1];
        String img3 = split[2];
        String img4 = split[3];
        System.out.println(img1);
        System.out.println(img2);
        model.addAttribute("img1",img1);
        model.addAttribute("img2",img2);
        model.addAttribute("img3",img3);
        model.addAttribute("img4",img4);
        model.addAttribute("style",style);
        return "style/mystyle";
    }

    //去添加我的装修
    @RequestMapping("/toAddStyle")
    public String toAddStyle(){
        return "style/addstyle";
    }
}

